<!DOCTYPE html>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title>竞价</title>
		<link href="css/text.css" rel="stylesheet" type="text/css" />
		<style type="text/css">						
			.fixedBox{
				border: 1px solid #555555;				
				white-space: nowrap;	
			}
			.fixedBox::-webkit-scrollbar {
				width: 12px;     
				height: 12px;				
			}			
			table{
			width:550px; 
			border-collapse:collapse; 
			text-align:center;
			}
			td,th{border:1px solid #696969}	
		</style>
	</head>
	<body>
		<div id="towrites" class="fixedBox" style="display:none;">
			<div class="fixedBox" style="position:relative;left:0px;width:2500px;height:550px;">	<!-- 宽度调节 -->	
				<div id="towrite" class="fixedBox"></div>	
				<iframe width="39%" height="550" id="mapIframe" name="mapIframe" src=""></iframe>
			</div>
		</div>
		
		<script type="text/javascript" src="js/json2html.js"></script>
		<script type="text/javascript" src="js/jquery.min.js"></script>
		<script type="text/javascript" src="DatePicker/WdatePicker.js"> </script>
		<script>
			var bkcolor = $("body").css("backgroundColor")
			var dt = "";
			var tt = "";
			var gt = "";
			var k = "0";
			window.onload = function() {
				var day = new Date();
				gt = day.getTime();
				mymonth = day.getMonth()+1;
				myday = day.getDate();
				if(mymonth >= 10){mymonth = mymonth;}else{mymonth = "0" + mymonth;}
				if(myday >= 10){myday = myday;}else{myday = "0" + myday;}
				tt = day.getFullYear() + "-" + mymonth + "-" + myday;
				dt = tt;
				getSource();
				changeStyle();
				
				var iframe = document.getElementById('mapIframe');				
				iframe.src = "精选板块轮动(折线图+最高板+5).html";	
			}
						
			function time_range(beginTime, endTime) {
				var strb = beginTime.split(":");
				if (strb.length != 2) {
					return false;
				}

				var stre = endTime.split(":");
				if (stre.length != 2) {
					return false;
				}

				var b = new Date();
				var e = new Date();
				var n = new Date();

				b.setHours(strb[0]);
				b.setMinutes(strb[1]);
				e.setHours(stre[0]);
				e.setMinutes(stre[1]);

				if (n.getTime() - b.getTime() > 0 && n.getTime() - e.getTime() < 0) {					
					getSource();
					changeCss(objt,"gg");					
					console.log(true)　　　　　　
					return true;				
				} else {
					console.log(false)
				    return false;     
				}
			}　　　
   　　　
			$(function() {
				setInterval(function() {
				time_range("9:00","15:15")						
				},
				60000);
			})
			
			Date.prototype.Format = function (fmt) {
			var o = {
				"M+": this.getMonth() + 1, //月份
				"d+": this.getDate(), //日
				"h+": this.getHours(), //小时
				"m+": this.getMinutes(), //分
				"s+": this.getSeconds(), //秒
				"q+": Math.floor((this.getMonth() + 3) / 3), //季度
				"S": this.getMilliseconds() //毫秒
			};			
			if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
				for (var k in o)
				if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
				return fmt;
			};
			
			function changeStyle() {
				var div = document.getElementById("towrites");
				div.style.display= "block";
				//div.style.position= "relative"; 				
				div.style.left= "0px"; 				
				div.style.width= "1350px";
				div.style.height= "550px";
				//div.style.border= "2px solid #fff"
				
				var obj1 = document.getElementById("towrite");
				obj1.style.position= "relative";
				obj1.style.marginTop= "-10px";
 				obj1.style.float= "left";
				obj1.style.left= "0px"; 				
				obj1.style.width= "870px";	
				//obj1.style.height= "100%";		
				obj1.style.fontSize= "12px";
				obj1.style.border= "1px solid #DCDCDC";
				
				var obj2 = document.getElementById("mapIframe");
				obj2.style.position= "relative"; 
				obj2.style.float= "left";
				obj2.style.marginLeft= "10px";
				//obj2.style.left= "0px"; 				
				obj2.style.width= "1200px";	
				//obj2.style.height= "100%";		
				obj2.style.fontSize= "12px";
				//obj2.style.border= "1px solid #fff";
			}
			
			function keepTwoDecimal(num) {  
               var result = parseFloat(num);  
               if (isNaN(result)) {  
                   //alert('传递参数错误，请检查！');  
                   return false;  
               }  
               result = Math.round(num * 100) / 100;  
               return result;  
			};
			
			
			function NumberTransform(num) { 
				var result = num;
               if(Math.abs(num) > 100000000){
			    result = num / 100000000;
				result = result.toFixed(2) + "亿";
			   }else if(Math.abs(num) > 10000){
			    result = num/10000;
				result = result.toFixed(0) + "万";
			   }				   
               return result;  
			};	
			
			var xt = 1; //涨停原因相同行高亮（1:true; 0:false;）
			var trid = "";
			var trs = "";
			var objt = "";
			function changeCss(obj,id){	
				if(obj){
					trs = "";
					objt = obj;
					var t = obj.parentNode.parentNode.id;  //td父节点tr id
					var ty = t.split("#")[1];
					var ty1 = "";
					var ty2 = "";
					if(ty.indexOf("、") > -1){
						ty1 = ty.split("、")[0];
						ty2 = ty.split("、")[1];
					}
					
					var tlist = document.getElementById(id).getElementsByTagName("tr");					
					for(var i = 0; i < tlist.length; i++){
						if(tlist[i].id != ""){
							var dm = tlist[i].id.split("#")[0];
							var yy = tlist[i].id.split("#")[1];
							if(xt == 1){   //涨停原因相同行高亮
								if(t == tlist[i].id){
									tlist[i].style.backgroundColor = "#483D8B";  //选中行
									trid = t;
								}else if(ty.indexOf("、") > -1){
									if(yy.indexOf(ty1) > -1 || yy.indexOf(ty2) > -1){
										tlist[i].style.backgroundColor = "#800080"; //相同涨停原因
										trs += tlist[i].id;
									}else{
										tlist[i].style.backgroundColor = bkcolor; 				
									}	
								}else{
									if(yy.indexOf(ty) > -1){
										tlist[i].style.backgroundColor = "#800080"; //相同涨停原因
										trs += tlist[i].id;
									}else{
										tlist[i].style.backgroundColor = bkcolor; 				
									}	
								}	
							}else{
								if(t == tlist[i].id){
									tlist[i].style.backgroundColor = "#483D8B";  //选中行
									trid = t;
								}else{
									tlist[i].style.backgroundColor = bkcolor; 				
								}	
							}							
						}					
					}				
				}
			}
			
			function hover(){  //鼠标经过
				var rows = document.getElementsByTagName('tr');
				for(var i=0;i<rows.length;i++){				
					rows[i].onmouseover=function(){							
						if(this.id != ""){  //过滤表头
							this.style.background="#800000";							
						}
					}
					rows[i].onmouseout=function(){						
						if(this.id != ""){  //过滤表头
							if(this.id == trid){  //过滤选中行
								this.style.background="#483D8B";
							}else if(trs.indexOf(this.id) > -1){
								this.style.background="#800080";
							}else{
								this.style.background=bkcolor;
							}
						}						
					}					
				}
			}			
			
			function hover1(){  //鼠标经过 相同主题高亮
				var rows = document.getElementsByTagName('tr');
				for(var i=0;i<rows.length;i++){				
					rows[i].onmouseover=function(){							
						if(this.id != ""){  //过滤表头
							//this.style.background="#800000";
							
							var ty = this.id.split("#")[1];
							var tlist = document.getElementsByTagName("tr");					
							for(var i = 0; i < tlist.length; i++){
								var dm = tlist[i].id.split("#")[0];
								var yy = tlist[i].id.split("#")[1];	
								if(trid !="" && tlist[i].id == trid){  
									tlist[i].style.background="#483D8B";
								}else if(this.id == tlist[i].id){
									tlist[i].style.backgroundColor = "#800000";  //选中行									
								}else if(ty == yy){
									tlist[i].style.backgroundColor = "#800080"; //相同涨停原因									
								}else{
									tlist[i].style.backgroundColor = bkcolor; 				
								}						
							}							
						}
					}
					
						
				}
			}			
			
			var ts = "";				
			function cDayFunc(dp) { 
				var date = dp.cal.getNewDateStr();            
				BookingRmk(date);//调用其它函数并带上参数                
			}
			
			function BookingRmk(date){         
				tt = date;
				var date1 = new Date(tt);
				var date2 = new Date(dt);							
				k = 0;
				if(date1.getTime() < date2.getTime()){			
					k = 1;
					tradeday();
				}								
				getSource();

				mapIframe.window.BookingRmk(tt);
			}

			function prev(){  //前一天
				pn = -1;
				var day = new Date(tt);	
				day.setTime(day.getTime() - 24*60*60*1000);	
				tt = day.Format("yyyy-MM-dd");
				BookingRmk(tt);
				
				mapIframe.window.BookingRmk(tt);
			}
			
			function next(){  //后一天 				
				pn = 1;
				var day = new Date(tt);	
				day.setTime(day.getTime() + 24*60*60*1000);	
				tt = day.Format("yyyy-MM-dd");
				BookingRmk(tt);			
				
				mapIframe.window.BookingRmk(tt);
			}
			
			var pn = -1;
			function tradeday() {  //判断最后交易日
				var day = new Date(tt);							
				for (i = 1; i < 100; i++){	//节假日																										
					if(i > 1){
						day.setTime(day.getTime() + pn*24*60*60*1000);							
					}	
					tt = day.Format("yyyy-MM-dd");
					//alert(tt);
					if(tt == dt){	
						k = 0;
						getSource();
						break;
					}
					var url = "http://127.0.0.1:8881/w1/api/index.php?Order=1&a=HisDaBanList&st=10&c=HisHomeDingPan&PidType=8&apiv=w26&Type=18&Is_st=1&Day=" + tt;
					var res = [];
					$.ajax({
						type: "get",
						url: url,
						dataType: "json",
						async : false,
						cache:false,
						timeout:3000,						
						success: function(data) {							
							res = data.list;							
						}
					});
					if(res.length != 0){						
						break;
					}
				}
			}	
			
			function getSource() {
				
				var div = document.getElementById('towrite');
				div.innerHTML = '<font size="4">竞价涨停委买&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><input style="width: 120px;" type="text" id="PriceDate" name="PriceDate" class="Wdate" onFocus="WdatePicker({ onpicking: cDayFunc})" />';						
				var back = '<a href="javascript:prev();"  style="padding-left:10px;font-size:16px;color:#fff;">←</a>';				
				var forward = '<a href="javascript:next();"  style="font-size:16px;color:#fff;">→</a>';
				div.innerHTML += back + forward + '<br><br>';
				
				var url1 = "http://127.0.0.1:8880/w1/api/index.php?Order=1&a=DaBanList&st=60&apiv=w26&Type=18&c=HomeDingPan&PidType=8&Is_st=1";				
				var url2 = "http://127.0.0.1:8881/w1/api/index.php?Order=1&a=HisDaBanList&st=5000&c=HisHomeDingPan&PidType=8&apiv=w26&Type=18&Is_st=1&Day=" + tt + "&";
				url = url1;
				if(k == "1" ){
				  url = url2;
				}
				<!-- createXmlHttp(); -->
				<!-- xmlHttp.onreadystatechange = writeSource; -->
				<!-- xmlHttp.open("GET", url, true); -->
				<!-- xmlHttp.send(null); -->
				
				var res = [];
				$.ajax({
					type: "get",
					url: url,
					dataType: "json",
					async : false,
					cache:false,
					timeout:3000,					
					success: function(data) {
						//alert(JSON.stringify(data))						
						//document.write(JSON.stringify(data));							
						if(k == 0){
							tt = data.day;							
							dt = tt;
						}
						
						for (i = 0; i < data.list.length; i++){
							res.push({"code":data.list[i][0],"name":data.list[i][1],"zf":data.list[i][4],"jjzf":data.list[i][19],"jjhs":data.list[i][21],"sjlt":data.list[i][15],"wme":data.list[i][18],"je":data.list[i][20],"jjcje":data.list[i][22],"zl":data.list[i][3],"lb":data.list[i][9],"bk":data.list[i][11]});							
						}											
					}
				});				
				writeSource(res);
			}
			
			var gl = "委买额";  //高亮
			var bj = [];
			function writeSource(data){
				var json = data;
				//创建table					
				var table=document.createElement("table");										
				var thead=document.createElement("thead");
				table.appendChild(thead);					
				var tr=document.createElement("tr");
				thead.appendChild(tr);					
				
				var m = 0;
				var v = 0;
				var b = 0;
				bj = [];
				for(var key in json[0]){  //表头													
					key = key.replace('code','代码').replace('name','名称').replace('jjzf','竞价涨幅%').replace('zl','主力').replace('wme','委买额');
					key = key.replace('lb','连板').replace('bk','板块').replace('zf','实时涨幅%').replace('jjcje','竞价成交额').replace('je','净额').replace('jjhs','竞价换手%').replace('sjlt','实际流通');
					var th=document.createElement("th");						
					th.innerHTML=key;						
					tr.appendChild(th);
					if(gl == key.replace("%","")){
						v = m;
						th.style.color = "#FF6633";	
					}
					<!-- if(key == "主力"){ -->
						<!-- b = m;							 -->
						<!-- th.style.color = "#FFA500"; -->
						
					<!-- }else if(key == "连板" || key == "板块"){ -->
						<!-- th.style.color = "#FFA500";	 -->
					<!-- } -->
					if(key == "主力" || key == "连板" || key == "板块"){
						bj.push(m);
						th.style.color = "#FFA500";	
					}
					m++;
				}
									
				var tbody=document.createElement("tbody");					
				table.appendChild(tbody);
				
				//遍历json
				for(var i = 0; i < json.length; i++){					
					var tr=document.createElement("tr");						
					var p = 1;
					var dm = "";
					var mc = "";
					var zt = "";						
					for(var key in json[i]){ //行元素遍历					
						var td=document.createElement("td");							
						
						var rc = json[i][key];
						if(p == 1){  //代码列
							dm = rc;								
						}else if(p == 3 || p == 4 || p == 5){
							rc = keepTwoDecimal(rc);
						}else if(p == 6 || p == 7 || p == 8 || p == 9){
							rc = NumberTransform(rc);
						}else if(p == 12){
							zt = rc;
							tr.id = dm + "#" + zt;
						}
						td.innerHTML = "<a href=http://www.treeid/code_" + dm + " id='" + p + "' onclick='changeCss(this,\"gg\")'>" + rc + "</a>";
						
						if(p == v + 1){							
							//td.getElementsByTagName("a")[0].style.color = "#FF6633";
							if(parseFloat(td.getElementsByTagName("a")[0].innerText) >= 0){
								td.getElementsByTagName("a")[0].style.color = "#FF6633";
							}else{
								td.getElementsByTagName("a")[0].style.color = "#00FF00";								
							}
						}
						<!-- if(p >= b + 1){							 -->
							<!-- td.getElementsByTagName("a")[0].style.color = "#FFA500"; -->
							<!-- //td.width = "100px";								 -->
						<!-- } -->
						if(bj.indexOf(p - 1) > -1){	 //需要BJ的列
							td.getElementsByTagName("a")[0].style.color = "#FFA500"; 
						}	

						tr.appendChild(td);
						p++;
					}						
					tbody.appendChild(tr);
				}					
				var div = document.getElementById("towrite");									
				div.appendChild(table);
				table.id = "gg";										
				//var table=document.getElementsByTagName("table")[0];
				makeSortable(table);
				//changeTable(table,"7#9#10"); //隐藏某列
				
				document.getElementById("PriceDate").value = tt;
				hover();			
			}			
			
			//隐藏某列				
            function changeTable(table,ss) {	
				var trs = table.rows;
				ss = ss + '#';
				var aa = ss.split('#');
				for (var j = 0; j < aa.length; j++) {
					if(aa[j] != ""){
						for (var i = 0, len = trs.length; i < len; i++) {					
							var p = aa[j];
							var cell = trs[i].cells[p]; 
							cell.style.display = 'none';
						}
					}
				}					
			}
			
			function makeSortable(table) {
				var headers=table.getElementsByTagName("th");
				for(var i=0;i<headers.length;i++){				
					(function(n){
						var flag=false;
							
						headers[n].onclick=function(){
							//alert(n);						
							showCol(n,bj);		//高亮
							var tbody=table.tBodies[0];
							var rows=tbody.getElementsByTagName("tr");
							rows=Array.prototype.slice.call(rows,0);

							//基于第n个<td>元素的值对行排序
							rows.sort(function(row1,row2){
								headtxt = headers[n].textContent;								
								var cell1=row1.getElementsByTagName("td")[n];//获得第n个单元格
								var cell2=row2.getElementsByTagName("td")[n];																
								var val1=cell1.textContent||cell1.innerText;//获得文本内容
								var val2=cell2.textContent||cell2.innerText;
								if(headtxt.indexOf("名称") != -1 || headtxt.indexOf("主力") != -1 || headtxt.indexOf("连板") != -1 || headtxt.indexOf("主题") != -1){
									val1 = val1;
									val2 = val2;
								}else{
									if(val1 == "-"){
										val1 = " ";
									}
									if(val2 == "-"){
										val2 = " ";
									}
									val1 = val1.replace(" ","0").replace("无","1000").replace("NaN","0");
									val2 = val2.replace(" ","0").replace("无","1000").replace("NaN","0");
									if(val1.indexOf("万") != -1){
										val1 = parseFloat(val1)*10000;
									}else if(val1.indexOf("亿") != -1){
										val1 = parseFloat(val1)*100000000;
									}else{
										val1 = parseFloat(val1);
									}
									
									if(val2.indexOf("万") != -1){
										val2 = parseFloat(val2)*10000;
									}else if(val2.indexOf("亿") != -1){
										val2 = parseFloat(val2)*100000000;
									}else{
										val2 = parseFloat(val2);
									}
								}
								if(val1<val2){
									return -1;
								}else if(val1>val2){
									return 1;
								}else{
									return 0;
								}
							});
							if(flag){
								rows.reverse();
							}
							
							for(var i=0;i<rows.length;i++){
								tbody.appendChild(rows[i]);
							}

							flag=!flag;
						}
					}(i));
				}
			}
			
			function showCol(iCol,arr){	 //(选中列，标记列)	
				var oTable = document.getElementsByTagName('table')[0];						
				//表头
				var th = oTable.getElementsByTagName("th");						
				for (var i=0;i < th.length; i++){	    //列遍历
					th[i].style.color = "#E5E5E5";      //还原					
					if(arr.length > 0 && arr.indexOf(i) > -1){  //BJ列高亮
						th[i].style.color = "#FFA500";
					}
					th[iCol].style.color = "#FFFF80";	//选中				
				}
				
				var tr = oTable.getElementsByTagName("tr");	
				for (var i=1;i < tr.length; i++){	//行遍历
					var otagsA = tr[i].getElementsByTagName("a");
					for (var j=0;j < otagsA.length; j++){	//列遍历
						otagsA[j].style.color = "#E5E5E5";	//还原																
						if(arr.length > 0 && arr.indexOf(j) > -1){  //BJ列高亮
							otagsA[j].style.color = "#FFA500";
						}
					}
					var value = otagsA[iCol].innerText.replace(/(万)|(亿)/g,'');
					if(!isNaN(parseFloat(value)) && isFinite(value)){  //判断列是否为数字
						if(parseFloat(value) >= 0){
							otagsA[iCol].style.color = "#FF6633";     //正负颜色
						}else{
							otagsA[iCol].style.color = "#00FF00";
						}
					}else{
						otagsA[iCol].style.color = "#FF6633";
					}					
				}					
			}	
			
		</script>	
	</body>
</html>